package design.jdkProxy;

import java.lang.reflect.Proxy;

public class ProxyFactory {
    public static Object getProxyInstance(Object target) {
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    System.out.println("intercept before");

                    Object res = method.invoke(target, args);

                    System.out.println("intercept after");
                    return res;
                }
        );
    }
}
